package com.techstar.mqttprocesser.service.mqtt.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author lilei
 * @create 2025-03-28-2025/3/28
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@TableName("MQTT_JSON_PARSE_CONFIG")
public class MqttJsonParseConfig {

    @TableField("DEVICE_NAME")
    private String deviceName;

    @TableField("TOPIC")
    private String topic;

    //字段名称
    @TableField("FIELD_NAME")
    private String fieldName;

    //字段类型
    @TableField("FIELD_TYPE")
    private String fieldType;

    //JSON路径
    @TableField("JSON_PATH")
    private String jsonPath;

    //是否必须(0:否,1:是)
    @TableField("REQUIRED")
    private int required;


    /**
     * 检查是否重复
     * @param config
     * @return true:重复,false:不重复
     */
    public boolean checkUnique(MqttJsonParseConfig config) {
        return  this.deviceName.equals(config.getDeviceName()) &&
                this.topic.equals(config.getTopic()) &&
                this.fieldName.equals(config.getFieldName());
    }

}
